package com.ruoyi.purchase.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.purchase.domain.AllocationDetail;
import com.ruoyi.purchase.service.IAllocationDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * AllocationDetailController
 * 
 * @author kevinness
 * @date 2025-01-18
 */
@RestController
@RequestMapping("/AllocationDetail")
public class AllocationDetailController extends BaseController
{
    @Autowired
    private IAllocationDetailService allocationDetailService;

    /**
     * 查询AllocationDetail列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AllocationDetail allocationDetail)
    {
        startPage();
        List<AllocationDetail> list = allocationDetailService.selectAllocationDetailList(allocationDetail);
        return getDataTable(list);
    }

    /**
     * 导出AllocationDetail列表
     */
    @Log(title = "AllocationDetail", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AllocationDetail allocationDetail)
    {
        List<AllocationDetail> list = allocationDetailService.selectAllocationDetailList(allocationDetail);
        ExcelUtil<AllocationDetail> util = new ExcelUtil<AllocationDetail>(AllocationDetail.class);
        util.exportExcel(response, list, "AllocationDetail数据");
    }

    /**
     * 获取AllocationDetail详细信息
     */
    @GetMapping(value = "/{allocationNo}")
    public AjaxResult getInfo(@PathVariable("allocationNo") String allocationNo)
    {
        return success(allocationDetailService.selectAllocationDetailByAllocationNo(allocationNo));
    }

    /**
     * 新增AllocationDetail
     */
    @Log(title = "AllocationDetail", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AllocationDetail allocationDetail)
    {
        return toAjax(allocationDetailService.insertAllocationDetail(allocationDetail));
    }

    /**
     * 新增调拨详情列表
     */
    @PostMapping("/insert/list")
    public AjaxResult addList(@RequestBody List<AllocationDetail> allocationDetailList){
        return toAjax(allocationDetailService.insertAllocationDetailList(allocationDetailList));
    }

    /**
     * 修改AllocationDetail
     */
    @Log(title = "AllocationDetail", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AllocationDetail allocationDetail)
    {
        return toAjax(allocationDetailService.updateAllocationDetail(allocationDetail));
    }

    /**
     * 删除AllocationDetail
     */
    @Log(title = "AllocationDetail", businessType = BusinessType.DELETE)
	@DeleteMapping("/{allocationNos}")
    public AjaxResult remove(@PathVariable String[] allocationNos)
    {
        return toAjax(allocationDetailService.deleteAllocationDetailByAllocationNos(allocationNos));
    }
}
